<?php

namespace backend\models;

use Yii;

class Campus extends \common\models\Campus
{
    public function rules()
    {
         return array_merge([
            [['FZRGH'], 'match', 'pattern' => '/^[a-zA-Z0-9]+$/','message' => '该项填写内容包含非法字符'],  // 代号类字段
            [['YZBM', 'DHHM'], 'match', 'pattern' => '/^\d+$/','message' => '该项填写内容应为纯数字'],  // 纯数字类字段
            [['CJSJ'], 'date', 'format' => 'php:Y-m-d', 'message' => '错误的日期格式，请重新修改'],
            [['XQYWMC'], 'match', 'pattern' => '/^[a-zA-Z0-9\s]+$/','message' => '字符类型超出限制'],
            [['DZYX'], 'email'],
            [['DHHM'], 'string', 'length' => [7, 11], 'message' => '电话号码位数应在7位到11位之间'],
            [['YZBM'], 'string', 'length' => 6, 'message' => '邮编是6位数字'],          
         ], parent::rules());
    }

    /////////////// 新建初始记录 ///////////////
    public function createNewRecord($id)
    {
        $campusModel = new Campus();
        $campusModel->XXID = $id;
        $campusModel->XQMC = '待补充';
        $campusModel->XQYWMC = '待补充';
        $campusModel->FZRXM = '待补充';
        $campusModel->DZ = '待补充';
        $campusModel->YZBM = '待补充';
        $campusModel->DHHM = '待补充';
        $campusModel->DZYX = '待补充';
        $campusModel->JJ = '待补充';
        $campusModel->CJSJ = date('Y-m-d', time());
        $campusModel->ZT = '正常';
        $campusModel->save(false);
        return $campusModel;
    }
}